#include <renderer.h>
#include <clip.h>
#include <utility_math.h>
#include <obj_parser.h>
#include <log.h>
#include <logImGui.h>

void Renderer::render(Vertex& vert1, Vertex& vert2, Vertex& vert3, Framebuffer& buffer) {
    mShader->VertexShader(vert1, vert2, vert3);

    vert1.position = divW(vert1.position);
    vert2.position = divW(vert2.position);
    vert3.position = divW(vert3.position);

    std::vector<std::tuple<Vertex, Vertex, Vertex>> triangles = clipping(vert1, vert2, vert3);
    if (triangles.size() == 0) {
        return;
    }
    
    if (!backCulling(triangles[0], Vec3f{0, 0, -1})) {
        return;
    }

    for (auto& [v1, v2, v3] : triangles) {
        v1.position = mViewportMat * v1.position;
        v2.position = mViewportMat * v2.position;
        v3.position = mViewportMat * v3.position;

        mResterizer.rasterization(v1, v2, v3);
    }
}